fix(ios): resolve pauseUnity, memory leaks, and Fabric issues#7
Closed
fix(ios): resolve pauseUnity, memory leaks, and Fabric issues#7
Conversation
Fix pauseUnity parameter type from BOOL* (pointer) to BOOL — the pointer was always non-nil, so Unity always paused and never resumed. Fix memory leak in initUnityModule where strdup'd strings and malloc'd array were never freed. Pass dictionary (not nil) to onPlayerUnload/onPlayerQuit callbacks to prevent potential crashes. Add unregisterAPIforNativeCalls to clear NativeCallProxy's strong reference on unload. Guard sendMessageToMobileApp against nil api. Fix ViewManager using file-global unity variable instead of the resolved view from viewRegistry. Fix Fabric prepareForRecycle destroying the singleton Unity runtime. Wire up onPlayerUnload and onPlayerQuit event emitters for Fabric (New Arch). Fix Fabric onUnityMessage lambda to use weak self instead of capturing raw C++ pointer. Respect androidKeepPlayerMounted in componentWillUnmount. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fix 8 iOS-side bugs in the Unity player lifecycle: broken pause/resume, memory leaks, crash-prone callbacks, and incomplete Fabric (New Architecture) support.
Why
Audit sessions identified these as HIGH and MEDIUM severity issues affecting all iOS users:
pauseUnity:never actually resumed — theBOOL *parameter type meant the pointer was always non-nil (truthy), so[[self ufw] pause:pause]always receivedtrueinitUnityModuleleaked memory on every init (strdup'd argv strings + malloc'd array never freed)onPlayerUnload/onPlayerQuitpassed nil to RCTBubblingEventBlock, risking crashesunityvariable instead of the resolvedviewfrom viewRegistryprepareForRecycledestroyed the singleton Unity runtime, breaking it for any future viewsonUnityMessageevent emitter —onPlayerUnloadandonPlayerQuitwere silentonUnityMessagelambda capturedselfas raw C++ pointer — dangling pointer riskHow
pauseUnity:(BOOL *)topauseUnity:(BOOL)in header, implementation, and ViewManagerrunEmbeddedWithArgc:consumes them@{@"message": @"unloaded"}/@{@"message": @"quit"}instead of nilunregisterAPIforNativeCallsmethod, call it inunloadUnity, guardsendMessageToMobileAppagainst nil apiunitywith resolvedviewin all ViewManager methodsunloadApplicationfromprepareForRecycle— only detach subviewsonPlayerUnloadandonPlayerQuitevent emitters in FabricinitWithFrame__weak/__strongself pattern in all Fabric event blocksandroidKeepPlayerMountedprop incomponentWillUnmountTesting
No automated test runtime available for native code. Changes verified by code review against UnityFramework API and React Native bridging conventions. Each fix addresses a specific, documented failure mode.
Related
🤖 Generated with Claude Code